
import 'nordic_otas_plugin_platform_interface.dart';
import 'rtk_status.dart';
typedef NordicOtaPluginCallBack(NordicStatus type,int progress);

class NordicOtasPlugin {
  Future<String?> getPlatformVersion() {
    return NordicOtasPluginPlatform.instance.getPlatformVersion();
  }

  Future<bool> notice() {
    return NordicOtasPluginPlatform.instance.notice();
  }

  ///设置固件包路径
  void setFilePath(String path){
    return NordicOtasPluginPlatform.instance.setFilePath(path);
  }

  ///开始升级
  void startOta(){
    return NordicOtasPluginPlatform.instance.startOta();
  }

  void startAndroidOta(String name,String address) {
    NordicOtasPluginPlatform.instance.startAndroidOta(name, address);
  }

  void otaListener(NordicOtaPluginCallBack callBack){
    NordicOtasPluginPlatform.instance.otaListener((call){
      if(call.method == "sendMessage"){
        String data = call.arguments.toString();
        String d1 = data.split("@")[0];
        if(d1 == "1"){
          callBack(NordicStatus.STATUS_SEARCH_DEVICE_ING,0);
        }
        if(d1 == "2"){
          callBack(NordicStatus.STATUS_SEARCH_DEVICE_SUCC,0);
        }
        if(d1 == "3"){
          String d2 = data.split("@")[1];
          callBack(NordicStatus.STATUS_UPDATE_ING,int.parse(d2));
        }
        if(d1 == "4"){
          callBack(NordicStatus.STATUS_UPDATE_ERROE,0);
        }
        if(d1 == "5"){
          callBack(NordicStatus.STATUS_UPDATE_SUCC,0);
        }
        if(d1 == "6"){
          callBack(NordicStatus.STATUS_DEVICE_DISCONNECT,0);
        }
        if(d1 == "7"){
          callBack(NordicStatus.STATUS_FILE_ERROR,0);
        }
        if(d1 == "8"){
          callBack(NordicStatus.STATUS_OTHER_ERROR,0);
        }
      }
      return callBack(NordicStatus.STATUS_OTHER_ERROR,0);
    });
  }

}
